package com.zmn.oms.common.enums;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 渠道工单类型枚举
 *
 * @author linfeng
 * @since 2020/10/30 15:44
 */
public enum ConfChannelWorkOrderTypeEnum {

	/**
	 * values
	 */
	YYHT(1, "运营后台"),
	GCSAPP(2, "工程师APP"),
	FWSMH(3, "服务商门户"),
	THIRDAPI(4, "第三方API"),
	NOTALLOWED(5, "均不允许"),
	AUTOCANCEL(6, "自动取消");

	/**
	 * 运营后台
	 */
	public static final int CONSTS_YYHT = 1;
	/**
	 * 工程师APP
	 */
	public static final int CONSTS_GCSAPP = 2;
	/**
	 * 服务商门户
	 */
	public static final int CONSTS_FWSMH = 3;
	/**
	 * 第三方API
	 */
	public static final int CONSTS_THIRDAPI = 4;
	/**
	 * 均不允许
	 */
	public static final int CONSTS_NOTALLOWED = 5;
	/**
	 * 自动取消
	 */
	public static final int CONSTS_AUTOCANCEL = 6;

	private Integer code;
	private String name;

	ConfChannelWorkOrderTypeEnum(Integer code, String name) {
		this.code = code;
		this.name = name;
	}

	public Integer getCode() {
		return code;
	}

	public String getName() {
		return name;
	}

	public static ConfChannelWorkOrderTypeEnum of(Integer code) {
		if (code == null) {
			return null;
		}
		switch (code) {
			case 1:
				return YYHT;
			case 2:
				return GCSAPP;
			case 3:
				return FWSMH;
			case 4:
				return THIRDAPI;
			case 5:
				return NOTALLOWED;
			case 6:
				return AUTOCANCEL;
			default:
				return null;
		}
	}

	public static String getName(Integer code) {
		ConfChannelWorkOrderTypeEnum of = of(code);
		return of == null ? null : of.getName();
	}

	public static ConfChannelWorkOrderTypeEnum[] completeOrCancelType() {
		return new ConfChannelWorkOrderTypeEnum[]{YYHT, GCSAPP, FWSMH, THIRDAPI, AUTOCANCEL};
	}

	public static ConfChannelWorkOrderTypeEnum[] specialOfferType() {
		return new ConfChannelWorkOrderTypeEnum[]{YYHT, GCSAPP, FWSMH, NOTALLOWED};
	}

	public static String getIncludeName(String code) {
		String[] codes = code.split(",", -1);
		List<String> list = new ArrayList<>();
		Arrays.stream(codes).forEach(x -> {
			ConfChannelWorkOrderTypeEnum of = of(Integer.parseInt(x));
			if (null != of) {
				list.add(of.getName());
			}
		});
		return String.join(",", list);
	}
}
